<template>
  <a-modal title="代理列表" :width="1000" :visible="visible" @ok="" @cancel="visible=false">
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="状态">
                <a-select v-model="state" placeholder="请选择医生状态">
                  <a-select-option :value="0">全部</a-select-option>
                  <a-select-option :value="1">销售人员</a-select-option>
                  <a-select-option :value="2">外部销售</a-select-option>
                  <a-select-option :value="2">省份代理</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <!-- <a-col :md="12" :sm="24">
              <a-button type="primary" @click="handleSearch">查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearch">重置</a-button>
              <a-button type="primary" style="margin-bottom: 8px" icon="plus" @click="addStore">
                添加代理</a-button>
            </a-col> -->
          </a-row>
        </a-form>
      </div>
      <a-table :scroll="{ x: true }" ref="table" @change="tablePaginationChange" :pagination="pagination" bordered
        :dataSource="dataSource" :columns="columns" :rowKey="(record,index)=> index">
        <div slot="state" slot-scope="text, record" href="javascript:;">
          <a-tag color="blue" v-if="record.state==1">销售人员</a-tag>
          <a-tag color="green" v-else-if="record.state==2">外部销售</a-tag>
          <a-tag color="orange" v-else-if="record.state==3">省份代理</a-tag>
        </div>

        <div slot="action" slot-scope="text, record" href="javascript:;">
          <a-button size='small' type="link" @click="chooseItem(record)">
            选择
          </a-button>
        </div>
      </a-table>
    </a-card>
    <imgBox ref='preimg'></imgBox>
    <template #footer>
    </template>
  </a-modal>
</template>

<script>
  import {
    STable,
    Ellipsis,
  } from '@/components'
  import {
    salespersonList,
    salespersonDel
  } from '@/api/salesperson'
  import imgBox from '@/components/previewImg/index'

  import {
    ExclamationCircleOutlined
  } from '@ant-design/icons-vue';
  import {
    createVNode
  } from 'vue';
  import {
    Modal,
    message
  } from 'ant-design-vue';

  export default {
    components: {
      STable,
      Ellipsis,
      imgBox
    },
    data() {
      return {
        visible: false,
        state: 0,
        priceform: this.$form.createForm(this),
        pricevisible: false, //修改诊金指数
        searchflag: false,
        shenhe: 0, //审核
        status: 0, //状态
        addFlag: false,
        pagination: {
          current: 1, //默认当前叶数
          total: 0, // 数据总数 如果不设置就以绑定的数据量为准
          pageSize: 10, // 默认每页条数
          showSizeChanger: true, //是否可以改变 pageSize
          pageSizeOptions: ['10', '20', '40', '80', '100'], //可切换每叶数据条数
          showTotal: total => this.$t('共') + ' ' + `${total}` + ' ' + this.$t('条数据'), // 分页中显示总的数据
          hideOnSinglePage: false // 只有一页时是否隐藏分页器 true为不显示 false为显示
        },
        dataSource: [],
        columns: [{
            title: 'id',
            dataIndex: 'id',
            key: 'id',
            width: 70,
          },
          {
            title: '名称',
            dataIndex: 'name',
            key: 'name',
            ellipsis: true,
          },
          {
            title: '电话号',
            dataIndex: 'phone',
            key: 'phone',
          },
          {
            title: '省份',
            dataIndex: 'province',
            key: 'province',
          },
          {
            title: '身份证号码',
            dataIndex: 'cardid',
            key: 'cardid',
          },

          {
            title: '类型',
            dataIndex: 'state',
            key: 'state',
            scopedSlots: {
              customRender: 'state'
            }
          },
          {
            title: '操作',
            key: 'operation',
            fixed: 'right',
            width: 150,
            scopedSlots: {
              customRender: 'action'
            }
          }
        ],
        curdoc: 0,
        edittype: '', //修改类型
      }
    },
    created() {
      this.getList()
    },
    methods: {
      chooseItem(v) {
        this.$emit('change', v)
        this.visible = false
      },
      // 医生详情
      showDetail(v) {
        this.$router.push({
          path: '/doctorDetail',
          query: {
            id: v.id
          }
        })
      },
      // 修改诊金
      updatePrice() {
        var that = this
        const {
          priceform: {
            validateFields
          },
        } = this

        validateFields((errors, values) => {
          if (!errors) {
            if (this.edittype == 'kefu') {
              doctorKefu({
                id: this.curdoc,
                kefu: values.zhenfeibl
              }).then((res) => {
                if (res.code == 0) {
                  this.pricevisible = false
                  this.getList()
                }
              })
            } else if (this.edittype == 'zhenfei') {
              values.zhenfeibl = parseInt(values.zhenfeibl)
              doctorPriceSet({
                ...values,
              }).then((res) => {
                if (res.code == 0) {
                  this.pricevisible = false
                  this.getList()
                }
              })
            } else {
              values.zhongyaobl = parseInt(values.zhenfeibl)
              doctorZhongyaoSet({
                ...values,
              }).then((res) => {
                if (res.code == 0) {
                  this.pricevisible = false
                  this.getList()
                }
              })
            }
          }
        })
      },
      editPrice(val, edittype) {
        this.curdoc = val.id
        this.edittype = edittype
        this.pricevisible = true
        setTimeout(() => {
          if (edittype == 'kefu') {
            this.priceform.setFieldsValue({
              zhenfeibl: val.kefu
            })
          } else {
            this.priceform.setFieldsValue({
              zhenfeibl: edittype == 'zhenfei' ? val.zhenfeibl : val.zhongyaobl
            })
          }
        }, 500)
      },
      authInfo(val) {
        doctorAuth({
          id: val.id
        }).then(res => {
          message.info('审核成功');
          this.getList(0)
        })
      },
      previewImg(img) {
        this.$refs.preimg.initData(img)
      },
      getList() {
        salespersonList({
          pageNo: this.pagination.current,
          pageSize: this.pagination.pageSize,
          state: this.state
        }).then(res => {
          this.pagination.total = res.data.totalCount
          this.dataSource = res.data.data
        })
      },
      handleSearch() {
        this.searchflag = true
        this.pagination.current = 1
        this.getList()
      },
      resetSearch() {
        this.searchflag = false
        this.state = 0
        this.pagination.current = 1
        this.getList()
      },
      updateInfo(val) {
        this.addFlag = true
        this.$nextTick(() => {
          this.$refs.addBox.setUpdate(val)
        })
      },

      addCancel() {
        this.addFlag = false
      },
      AddSuccess() {
        this.addFlag = false
        this.getList()
      },
      addStore() {
        this.addFlag = true
        this.$nextTick(() => {
          this.$refs.addBox.updateflag = false
          this.$refs.addBox.setState()
        })
      },
      tablePaginationChange(e) {
        this.pagination = e
        this.getList()
      },
      getDate(stamp) {
        var date = new Date(stamp * 1000)
        return date.getFullYear() + '-' + (date.getMonth() + 1 < 10 ? ('0' + (date.getMonth() + 1)) : date
          .getMonth() +
          1) + '-' + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
      },
      deletInfo(val) {
        hospitalDelet(val.id).then(res => {
          this.getList()
        })
      },
      infoDisable(val) {
        salespersonDel({
          id: val.id
        }).then(res => {
          this.getList()
        })
      }
    }
  }
</script>
<style scoped>
  .banner-img {
    width: 50px;
    height: 50px;
    border-radius: 5px;
    cursor: pointer;
  }
</style>